document.onirkeypress = keyDown;
document.onkeydown = keyDown;
var isalone = getParam('isalone');
var chanceStatus = true;
var backurl = getParam('backurl');
var tv_no = "";
var tv_card = "";
try {
    tv_no = hardware.STB.serialNumber;
} catch (e) {
    tv_no = '033234001051700023B8000000';
}
try {
    tv_card = CA.card.serialNumber || '';
} catch (e) {
    tv_card = '9932058300001801';
}
function prompt(title) {
    //alert(title);
    // var str = '<div class="tishi" style="box-sizing:border-box;font-size: 30px;z-index: 1111;text-align: ' +
    //     'center;width: 800px;height: 120px;line-height:120px;position: absolute;background:#ffe488;border-radius: 20px;top: 280px;left: 300px;color: black;">' + title +
    //     '</div>';
        var mydiv = document.createElement('div');
        mydiv.className = 'tishi';
        mydiv.style.boxSizing = 'border-box';
        mydiv.style.fontSize = '30px';
        mydiv.style.width = '800px';
        mydiv.style.height = '120px';
        mydiv.style.position = 'absolute';
        mydiv.style.background = '#ffe488';
        mydiv.style.zIndex = 1111;
        mydiv.style.top = '280px';
        mydiv.style.left = '300px';
        mydiv.style.lineHeight = '120px';
        mydiv.style.textAlign = 'center';
        mydiv.style.color = 'black';
        mydiv.style.borderRadius = '20px';
        mydiv.innerText = title;
        //mydiv.innerText = title;

    //$("body").append(str);
    document.body.appendChild(mydiv);

    setTimeout(function () {
        //document.getElementsByClassName('tishi')[0].style.display='none';
        document.body.removeChild(mydiv);
    }, 50000);
};
function keyDown(evt) {
    evt = (evt) ? evt : ((window.event) ? window.event : "") //兼容IE和Firefox获得keyBoardEvent对象
    var keyCode = evt.keyCode ? evt.keyCode : evt.which;
    // prompt(keyCode);
    switch (keyCode) {
        case KEY.RIGHT:
        case KEY.RIGHT2:
            break;
        case KEY.LEFT:
        case KEY.LEFT2:
            break;
        case KEY.UP:
        case KEY.UP2:
            break;
        case KEY.DOWN:
        case KEY.DOWN2:
            break;
        // case KEY.EXIT:
        //     alert(1);
        //     if (!backurl) {
        //         Window.href = "./index.html"
        //     } else {
        //         Window.href = decodeURIComponent(backurl)
        //     }
            case KEY.ENTER:

                break;

            case KEY.BACK:
                // alert(1)
                if (!backurl) {
                    window.location.href = "./index.html"
                    // window.location.href = "./record.html"
                } else {
                  if(chanceStatus){
                    // window.location.href = decodeURIComponent(backurl)
                    window.location.href = './lottery.html'
                  }else {
                    window.location.href = "./index.html"
                  }
                }
                return 0;
                break;
    }
}
getChance()
function getChance() {
  var ajax;
  if (window.XMLHttpRequest) {
      ajax = new XMLHttpRequest();
  } else {
      ajax = new ActiveXObject('Microsoft.XMLHTTP');
  }
  ajax.onreadystatechange = function () {
      if (ajax.readyState == 4 && ajax.status == 200) {
        var text = ajax.responseText;
        //alert(text);
        var response;
        if (text.length != 0) {
            response = eval("(" + text + ")");
        }
        if(response.sts != 1) {
          chanceStatus = false
        }
        // console.log(response);  
        // alert(response) 
        // document.getElementById('tips').innerHTML = response + '1234'

      }
  }
  ajax.open('post', STATICURL + "activity/getRecord", true);
  ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  ajax.send('tv_no=' + tv_no + '&tv_card=' + tv_card + '&isalone=' + isalone + '&base_id=' + getCookie('base_id') );
  // $.ajax({
  //     url: STATICURL + "Lottery/lists",
  //     type: "POST",
  //     dataType: 'json',
  //     data: {
  //         tv_no: tv_no,
  //         tv_card: tv_card,
  //         base_id:base_id,
  //     },
  //     success: function (response) {
  //
  //         for (var i = 0; i < response.length; i++) {
  //             $('#prize' + (i + 1)).html(response[i].prize);
  //             if (response[i].img != null && response[i].img.length != 0) {
  // 			prizeArray.add(IMAGE + response[i].img);
  //                 $('#prize' + (i + 1)).css('background', 'url(' + (IMAGE + response[i].img) + ') no-repeat cover');
  //             }else{
  // 			prizeArray.add("");
  // 		}
  //
  //         }
  //     }
  // })
}